import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

//1.引入element-plus组件库及其样式
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
//2.引入element-plus图标库（起了一个别名ElementPlusIconsVue）
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
//6.1修改elementPlus默认中文
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'

const app = createApp(App) /* 创建Vue实例 */
//3.将所有导入的图标组件变为键值对数组，并依次遍历取出每一个图标组件[key,component]
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    //4.将当前遍历到的图标组件注册为当前Vue实例的全局组件
    app.component(key, component)
}
//5.为当前Vue实例安装element-plus组件库，并其他配置项，最后挂载到#app元素上
//6.2 app.use(ElementPlus,{ locale: zhCn })将El本地化为中文
app.use(ElementPlus,{ locale: zhCn }).use(store).use(router).mount('#app')

//7.解决ResizeObserver Error
const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}